using UnityEngine;

/// <summary>
/// �ο� https://blog.csdn.net/u014361280/article/details/103871840
/// </summary>
[RequireComponent(typeof(LineRenderer))]
public class DrawBezierLine : MonoBehaviour
{
    // ���α��������Ƶ�
    public Transform[] controlPoints;

    // LineRenderer 
    private LineRenderer lineRenderer;
    private int layerOrder = 0;

    // ���ñ�������ֵ����
    private int segmentNum = 50;
    private Vector3[] points3;

    void Start()
    {
        if (!lineRenderer)
        {
            lineRenderer = GetComponent<LineRenderer>();
        }
        lineRenderer.sortingLayerID = layerOrder;

        points3 = new Vector3[segmentNum];
    }

    void Update()
    {
        DrawThreePowerCurve();
    }


    void DrawThreePowerCurve()
    {
        // ��ȡ���α�������������
        Core.Utils.Bezier.GetThreePowerBezierList(ref points3, controlPoints[0].position, controlPoints[1].position, controlPoints[2].position, controlPoints[3].position);
        // ���� LineRenderer �ĵ����������ֵ��ֵ
        lineRenderer.positionCount = segmentNum;
        lineRenderer.SetPositions(points3);

    }
}
